
using System;
using System.Linq;
using Csla;
using Csla.Data;
using Csla.Security;
using Csla.Validation;

namespace HousingInfo.Library
{ 
	public partial class VipHouseBO : Csla.BusinessBase<VipHouseBO>
	{

		#region Authorization Rules
		protected override void AddAuthorizationRules()
		{
			//TODO: Define authorization rules in VipHouseBO
			//AuthorizationRules.AllowRead(VipHouseIDProperty, "VipHouseBOReadGroup");
			//AuthorizationRules.AllowRead(NewsHouseIDProperty, "VipHouseBOReadGroup");
			//AuthorizationRules.AllowRead(PriceProperty, "VipHouseBOReadGroup");
			//AuthorizationRules.AllowRead(RegisterDateProperty, "VipHouseBOReadGroup");
			//AuthorizationRules.AllowRead(NumRegisterProperty, "VipHouseBOReadGroup");
			//AuthorizationRules.AllowRead(IsActiveProperty, "VipHouseBOReadGroup");
			//AuthorizationRules.AllowRead(NumPostProperty, "VipHouseBOReadGroup");
			//AuthorizationRules.AllowRead(IsExtensionProperty, "VipHouseBOReadGroup");

			//AuthorizationRules.AllowWrite(NewsHouseIDProperty, "VipHouseBOWriteGroup");
			//AuthorizationRules.AllowWrite(PriceProperty, "VipHouseBOWriteGroup");
			//AuthorizationRules.AllowWrite(RegisterDateProperty, "VipHouseBOWriteGroup");
			//AuthorizationRules.AllowWrite(NumRegisterProperty, "VipHouseBOWriteGroup");
			//AuthorizationRules.AllowWrite(IsActiveProperty, "VipHouseBOWriteGroup");
			//AuthorizationRules.AllowWrite(NumPostProperty, "VipHouseBOWriteGroup");
			//AuthorizationRules.AllowWrite(IsExtensionProperty, "VipHouseBOWriteGroup");
		}

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of VipHouseBO
			//AuthorizationRules.AllowCreate(typeof(VipHouseBO), "VipHouseBOCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(VipHouseBO), "VipHouseBOEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(VipHouseBO), "VipHouseBODeleteGroup"));
		}
		#endregion //Authorization Rules
		private void AssignParentKey(HousingInfo.DataLinQ.VipHouse data)
		{
			 //data.ParentId = ReadProperty<ParentBO>(ParentBOProperty).Id;
        }
        #region lay 1 tin vip house theo id tin nha dat
        //khai bao ham
        public static VipHouseBO GetVipHouseBO_ByIDNewsHouses(int newsHouseID)
        {
            return DataPortal.Fetch<VipHouseBO>(new FilterCriteria_VipHouse_ByIdNewsHouse(newsHouseID));
        }
        //khai bao bien
        private class FilterCriteria_VipHouse_ByIdNewsHouse
        {
            public int idnewshouse;
            public FilterCriteria_VipHouse_ByIdNewsHouse(int id)
            {
                this.idnewshouse = id;
            }
        }
        //truy cap du lieu
        private void DataPortal_Fetch(FilterCriteria_VipHouse_ByIdNewsHouse criteria)
        {
            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                var data = mgr.DataContext.VipHouses
                        .Single(r => r.NewsHouseID == criteria.idnewshouse);

                OnMemberLoading(data);
                LoadProperty<int>(VipHouseIDProperty, data.VipHouseID);
                LoadProperty<int?>(NewsHouseIDProperty, data.NewsHouseID);
                LoadProperty<decimal?>(PriceProperty, data.Price);
                LoadProperty<DateTime?>(RegisterDateProperty, data.RegisterDate);
                LoadProperty<int?>(NumRegisterProperty, data.NumRegister);
                LoadProperty<bool>(IsActiveProperty, data.IsActive);
                LoadProperty<int?>(NumPostProperty, data.NumPost);
                LoadProperty<bool>(IsExtensionProperty, data.IsExtension);
                //OnMemberLoaded();

                ValidationRules.CheckRules();
            }//using

            //OnFetched();
        }
        #endregion
    }
}
